import fs from 'fs';
import path from 'path';
import express from 'express';
import querystring from 'querystring';

function adduser(req,res){
    //接受来自前端的数据请求；
    let buf=Buffer.alloc(0);
    req.on('data',chunk=>{
        buf=Buffer.concat([buf,chunk ])
    })
    req.on('end',()=>{
        //获取user.json;
        let filePath=path.join(__dirname,'../data/user.json')
        let {us}=querystring.parse(buf.toString());//键值对
        us=JSON.parse(us)
        let users=JSON.parse(fs.readFileSync(filePath));
        users.push(us)
        fs.writeFileSync(filePath,JSON.stringify(users),'utf-8')
        res.send('1')
    })
}
export {adduser}